// ===========================================================
// - TWEEN PROTOTYPE
// ===========================================================
// lord knows why, but i need to reference, not import
// one of the easing functions so the complier doesn't complain
mx.transitions.easing.Regular.easeIn;

/**
	FROM THE MM DOCS
	Back: Extends the animation beyond the transition range at one or both ends once to resemble an overflow effect.
	Bounce: Adds a bouncing effect within the transition range at one or both ends. The number of bounces relates to the duration—longer durations produce more bounces.
	Elastic: Adds an elastic effect that falls outside the transition range at one or both ends. The amount of elasticity is unaffected by the duration.
	Regular: Adds slower movement at one or both ends. This feature enables you to add a speeding-up effect, a slowing-down effect, or both.
	Strong: Adds slower movement at one or both ends. This effect is similar to Regular easing, but it's more pronounced.
	None: Adds an equal movement from start to end without effects, slowing, or speeding up. This transition is also referred to as a linear transition.
	The previous six easing classes each have three easing methods:

	easeIn: Provides the easing effect at the beginning of the transition.
	easeOut: Provides the easing effect at the end of the transition.
	easeInOut: Provides the easing effect at the beginning and end of the transition.
*/
MovieClip.prototype.tween = function(
	prop,
	method,
	begin,
	finish,
	duration,
	useSeconds) {
//		mx.transitions.easing.Regular;
		//  get the name
		var hname = '_tween_manager';
		while (this[hname]) {
			if (this[hname] instanceof mx.transitions.Tween) break;
			hname = '_' + hname;
		}
		// determine tween type
		if (!(method instanceof Function)) {
			var parts = method.split('.');
			method = mx.transitions.easing[parts[0]][parts[1]];
		}
		
		// default useSeconds to true
		if (useSeconds !== false) useSeconds = true;
		
		// now if prop is an array, add a tween for each item
		if (prop instanceof Array) {
			var b, f, d, tweens;
			for (var i=0; i<prop.length; i++) {
				b = (begin instanceof Array)?begin[i]:begin;
				f = (finish instanceof Array)?finish[i]:finish;
				d = (duration instanceof Array)?duration[i]:duration;
				tweens.push(this.tween(prop[i], method, b, f, d, useSeconds));
			}
			return tweens;
		}
		
		this[hname] = new mx.transitions.Tween(this, prop, method, begin, finish, duration, useSeconds);
		return this[hname];
}





// ===========================================================
// - REVERSE
// ===========================================================
MovieClip.prototype.reverse = function() {
	this.reverseTo(1);
}

MovieClip.prototype.reverseTo = function(frame) {
	if (this._isReversing) return;
	this._isReversing = true;
	this._reverseTargetFrame = frame;
	
	if (this.onEnterFrame) this._revereseOnEF = this.onEnterFrame;
	
	this.onEnterFrame = function() {
		var cf = this._currentframe;
		this.gotoAndStop(cf-1);
		if (cf == this._reverseTargetFrame || cf < 2) {
			this.stopReverse();
		}
		this._revereseOnEF();
	}
}

MovieClip.prototype.stopReverse = function() {
	if (this._isReversing) {
		this._isReversing = false;
		delete(this._reverseTargetFrame);
		if (this._revereseOnEF) {
			this.onEnterFrame = this._revereseOnEF;
		} else {
			delete(this.onEnterFrame);
		}
	}
}

// ===========================================================
// - FRAME SHIFT
// ===========================================================
/*
===============================================================================
= FRAMESHIFT MOVIECLIP PROTOTYPE
=------------------------------------------------------------------------------
=
= Matthew Richmond <matthew@choppingblock.com>
= The Chopping Block, Inc.
= choppingblock.com
= 
=------------------------------------------------------------------------------
=
= Requires: none
=
=------------------------------------------------------------------------------
= Version: 1.0.0
= Latest changes:
=        (2005) july 17 (1.0.0) - first version
===============================================================================
*/

MovieClip.prototype.frameShift = function(fr, obj, callback, paramArray) {
	if (fr < this._currentframe) {
		this.reverseShift(fr, obj, callback, paramArray);
	} else {
		this.forwardShift(fr, obj, callback, paramArray);
	}
};

MovieClip.prototype.forwardShift = function(fr, obj, callback, paramArray) {
	var n = (!fr) ? 1 : fr;
	if (this._currentframe < n) {
      var mc = this;

		mc.onEnterFrame = function ():Void{
			if (mc._currentframe < n) {
				mc.nextFrame();
			} else {
				delete mc.onEnterFrame;
				obj[callback](paramArray);
			};
		};
	};
}
// Usage
//_root.studio_mc.forwardShift(10, _root, "doneFunction");

MovieClip.prototype.reverseShift = function(fr, obj, callback, paramArray) {
   var n = (!fr) ? 1 : fr;
   if (this._currentframe > n) {
      var mc = this;
		//trace("mc is "+mc);
		mc.onEnterFrame = function ():Void{
			//trace(this);
			if (mc._currentframe > n) {
			   mc.prevFrame();
         } else {
            delete mc.onEnterFrame;
				obj[callback](paramArray);
         }
		};
   };
};

// Usage
//_root.studio_mc.reverseShift(1, _root, "doneFunction");

MovieClip.prototype.sizeMe = function(const, targW, targH, obj, callback) {
	
	if (targW == undefined) {
		var targW = this._width;
	}
	
	if (targH == undefined) {
		var targH = this._height;
	}
	
	// each prototype is being hard coded to a specific depth
	// so it cleans itself out when a like tween is requested
	// if you make more make sure you give them a different value
	this.createEmptyMovieClip("size_mc", -1);
	this.size_mc.onEnterFrame = function() {
		//trace('sizeMe');
		this._parent.diffW = targW-this._parent._width;
		this._parent.diffH = targH-this._parent._height;
		this._parent._width += this._parent.diffW*const;
		this._parent._height += this._parent.diffH*const;
		if ((Math.abs(this._parent.diffW)<.25) && (Math.abs(this._parent.diffH)<.25)) {
			this._parent._width = targW;
			this._parent._height = targH;
			obj[callback]();
			delete (this.onEnterFrame);
			delete (this);
		};
	};
};

MovieClip.prototype.scaleMe = function(const, targS, obj, callback) {
	
	// each prototype is being hard coded to a specific depth
	// so it cleans itself out when a like tween is requested
	// if you make more make sure you give them a different value
	this.createEmptyMovieClip("scale_mc", -2);
	this.scale_mc.onEnterFrame = function() {
		//trace('sizeMe');
		this._parent.diffXS = targS-this._parent._xscale;
		this._parent.diffYS = targS-this._parent._yscale;
		this._parent._xscale += this._parent.diffXS*const;
		this._parent._yscale += this._parent.diffYS*const;
		if ((Math.abs(this._parent.diffXS)<.25) && (Math.abs(this._parent.diffYS)<.25)) {
			this._parent._xscale = targS;
			this._parent._yscale = targS;
			obj[callback]();
			delete (this.onEnterFrame);
			delete (this);
		};
	};
};

MovieClip.prototype.moveMe = function(const, targX, targY, obj, callback) {
	
	if (targX == undefined) {
		var targX = this._x;
	}
	
	if (targY == undefined) {
		var targY = this._y;
	}

	// each prototype is being hard coded to a specific depth
	// so it cleans itself out when a like tween is requested
	// if you make more make sure you give them a different value
	this.createEmptyMovieClip("move_mc", -3)
	this.move_mc.onEnterFrame = function() {
		//trace('moveMe');
		this._parent.diffX = targX-this._parent._x;
		this._parent.diffY = targY-this._parent._y;
		this._parent._x += this._parent.diffX*const;
		this._parent._y += this._parent.diffY*const;
		if ((Math.abs(this._parent.diffX)<.5) && (Math.abs(this._parent.diffY)<.5)) {
			this._parent._x = Math.round(targX);
			this._parent._y = Math.round(targY);
			obj[callback]();
			delete (this.onEnterFrame);
			delete (this);
		}
	};
};
 
 MovieClip.prototype.showMe = function(const, targA, obj, callback) {
	
	this._visible = true;

	// each prototype is being hard coded to a specific depth
	// so it cleans itself out when a like tween is requested
	// if you make more make sure you give them a different value	
	this.createEmptyMovieClip("show_mc", -4);
	this.show_mc.onEnterFrame = function() {
		//trace('moveMe');
		this._parent.diffA = targA-this._parent._alpha;
		this._parent._alpha += this._parent.diffA*const;
		if ((Math.abs(this._parent.diffA)<.25)) {
			this._parent._alpha = targA;
			if (targA == 0) {
				this._parent._visible = false;
			}
			obj[callback]();
			delete (this.onEnterFrame);
			delete (this);
		};
	};
};